package logic

import (
	"context"
	"fmt"
	"shop_srv/model/redis"

	"shop_srv/internal/svc"
	"shop_srv/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCartLogic {
	return &GetCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetCartLogic) GetCart(in *shop.GetCartRequest) (*shop.GetCartResponse, error) {
	// todo: add your logic here and delete this line
	cart, err := redis.GetCart(in.UserId)
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}
	return &shop.GetCartResponse{List: cart}, nil
}
